from Base.DataBase import mysqldb
from Base.DataCollect import DataCollect
from Base.PublicFunction import render_tem


class collect_report_data():
    def __init__(self):
        pass

    def getdata_from_db(self):
        result_list = mysqldb().read_data()
        DataCollect.execute_sum = result_list[0].get('total_excount')
        DataCollect.success_num = result_list[0].get('success_cases')
        DataCollect.fail_sum = result_list[0].get('failed_cases')
        DataCollect.percent = result_list[0].get('percent')
        DataCollect.test_start_time = result_list[0].get('start_time')
        DataCollect.test_end_time = result_list[0].get('end_time')
        DataCollect.test_duration_time =result_list[0].get('count_time')
        for result in result_list:
            detail_info_dict = {}
            detail_info_dict['caseid'] = result.get('case_id')
            detail_info_dict['desc'] = result.get('case_desc')
            detail_info_dict['module'] = result.get('case_module')
            detail_info_dict['res'] = result.get('actual_res')
            detail_info_dict['case_start_time'] =result.get('case_start_time')
            detail_info_dict['case_end_time'] = result.get('case_end_time')
            detail_info_dict['run_time'] = result.get('case_count_time')
            detail_info_dict['res_info'] =result.get('failed_info')
            detail_info_dict['opetator'] = result.get('opetator')
            DataCollect.case_detail_list.append(detail_info_dict)
            # print(DataCollect.case_detail_list)

        render_tem(DataCollect)



if __name__ == '__main__':
    cr = collect_report_data()
    cr.getdata_from_db()